/** 
 * This block will create an invisible sprite as a detection zone to triger it,
 * once trigered, it will fall to a given direction/speed. 
 * and finaly being deleted after 15 seconds
 * 
 * */

package blocks {
	import org.flixel.plugin.photonstorm.FlxDelay;
	
	
	public class FallingTrap extends Trap {
		
		public function FallingTrap(X:int, Y:int, infos:Object=null, mapName:String='') {
			
			super(X, Y, infos, mapName);
			
			var speed:Number = infos.speed ? infos.speed : 1;
			
			_triggerName = infos.triggerName;
			
			//create detection zone;
			if(infos.range){
				var ghost:GhostZone = new GhostZone(
					x - Math.floor(infos.range[0] / 2) * tileInfos.tileSize[0], 
					speed > 0 ? y : y - (infos.range[1] * tileInfos.tileSize[1]), 
					infos.range[0] * tileInfos.tileSize[0], infos.range[1] * tileInfos.tileSize[1],
					this
				);
			}
		}
		
		
		/**
		 * Called once triggered, or trespassed. 
		 * This will add gravity to this bloc and it'll begin to fall
		 * 
		 * @return	nothing
		 * 
		 * */
		override public function activate():void{
			super.activate();
			//solid = false;
			
			acceleration.y = infos.speed ? 
				infos.speed * Registry.gameInfos.world.gravity : 
				Registry.gameInfos.world.gravity;
			
			var delay:FlxDelay = new FlxDelay(10000);
			
			delay.callback = function():void{
				kill();
				active=false;
			};
			
			delay.start();
		}
		
		
	}
}
